package org.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Map;

import org.noka.gson.Gson;
import org.noka.gson.reflect.TypeToken;
import org.noka.tree.NTreeMoveNode;
import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.ServletNokaContext;



/**
 * 数型菜单移动节点实例
 * @author rebin
 *
 */
public class TreeMoveNode implements NTreeMoveNode{
	public String MoveNode(String path,String nodes) {
		StringBuffer body = new StringBuffer();
		Connection con = ServletNokaContext.getConnection();
		try{
			Gson gson = new Gson();
			List<Map<String,String>> nodeList = gson.fromJson(nodes,new TypeToken<List<Map<String,String>>>(){}.getType());
			try{
				con.setAutoCommit(false);
				PreparedStatement msta = con.prepareStatement("UPDATE nk_sys_treebook set tpid =? ,TLVIE=? WHERE tid =?");
				for(Map<String,String> m:nodeList){
					msta.setLong(1,Integer.parseInt(m.get("pid")));
					msta.setString(2,m.get("leve"));
					msta.setLong(3,Integer.parseInt(m.get("id")));
					msta.addBatch();
				}
				msta.executeBatch();
				con.commit();//提交事务
				msta.close();
				con.setAutoCommit(true);
			}catch(Exception se){
				con.rollback();//回滚事务
			}
			body.append("{\"code\":true,\"msg\":\"\"}");//以json对像返回,可自己定义属性
			return body.toString();
		}catch(Exception se){
			BugInfoWrint.Print(se);
		}
		body.append("{\"code\":false,\"msg\":\"update false\"}");//以json对像返回,可自己定义属性
		return body.toString();
	}
}
